<?php require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";
/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/


//所有任务
$dosql->Execute("SELECT `id` FROM `#@__order` WHERE   `jindu`=1 AND is_delete=0  ", 2);
$count2 = $dosql->GetTotalRow(2); //待派单
$dosql->Execute("SELECT `id` FROM `#@__order` WHERE   `jindu`=3  AND is_delete=0  ", 4);
$count4 = $dosql->GetTotalRow(4); //待接单

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE   `jindu`=4  AND is_delete=0  ", 5);
$count5 = $dosql->GetTotalRow(5); //未完成

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE   `jindu`=5  AND is_delete=0    ", 6);
$count6 = $dosql->GetTotalRow(6); //报修完成

$dosql->Execute("SELECT `id` FROM `#@__order` WHERE   `jindu`=6   AND is_delete=0   ", 7);
$count7 = $dosql->GetTotalRow(7); //报修完成

$jindu = empty($jindu) ? '' : htmlspecialchars($jindu); //进度状态
$jindu = intval($jindu);
$manageid = "";
if (isset($uid)) {

    //有session 从数据库中读取用户名信息
    //$openid_str=$_SESSION['openid'];
    $sql = "SELECT u.*,g.groupname  as groupname  FROM `#@__user` as u 
				   left join `#@__usergroup` as g  on u.level=g.id  
				   WHERE u.id='$uid' ";
    $row = $dosql->GetOne($sql);
    if (is_array($row) && isset($row['id'])) {
        // 返回用户 id
        $id = $row['id'];
        $_SESSION['id'] = $id;
        $userInfo = $row;
        $level = intval($row['level']);
    }
}

if ($level > 5) {
    exit();
}

switch ($jindu) {
    case 3:
        $order_title = "待接单";
        break;
    case 4:
        $order_title = "未完成";
        break;
    case 5:
        $order_title = "待评价";
        break;
    case 6:
        $order_title = "已评价";
        break;
    default:
        $order_title = "全部";
}

?>
    <!DOCTYPE html>
    <html>
    <head>
        <title><?php echo $cfg_webname; ?> </title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="description" content="<?php echo $cfg_webname; ?>">
        <link rel="stylesheet" href="lib/weui.min.css">
        <link rel="stylesheet" href="css/jquery-weui.css">
        <link rel="stylesheet" href="css/font-awesome.min.css">
        <link rel="stylesheet" href="css/demos.css?v=20201211.2129">
    </head>

<body ontouchstart>
<style>
    .weui-form-preview:after {

        border-bottom: none;

    }
</style>
<div class="top">
    <div class="user_top">
        <i>
            <?php
            if (intval($row['level']) > 1) {
                echo '<a href="manage.php">' . $userInfo['groupname'] . '</a>';
            } else {
                echo $userInfo['groupname'];
            } ?>
            UID:<?php echo $id; ?>
        </i>
        <div class="user_top_conn"><img src="<?php echo $userInfo['headimgurl'] ?>"/>
            <p><?php echo $userInfo['truename'] ?></p>
            <?php if (intval($row['level']) < 5) { ?><a class="user_link" href="member.php">返回用户</a><?php } ?>
        </div>
    </div>
</div>
<!-- 任务概况 -->

<div class="main">
    <!-- 工单状态 -->
    <div class="Order">
        <dl>
            <a href="morder.php">
                <dt><strong><i class="fa fa-server" aria-hidden="true"></i>所有任务</strong><span>查看全部任务</span></dt>
            </a>
        </dl>
        <ul>
            <?php if ($level < 3) { ?>
                <li>
                <a href="morder.php?jindu=1"><em class="ordem3"><i><?php echo $count2 ?></i></em><span>待派单</span></a>
                </li><?php } ?>
            <li><a href="morder.php?jindu=3"><em class="ordem1"><i><?php echo $count4 ?></i></em><span>待接单</span></a>
            </li>
            <li><a href="morder.php?jindu=4"><em class="ordem4"><i><?php echo $count5 ?></i></em><span>未完成</span></a>
            </li>
            <li><a href="morder.php?jindu=5"><em class="Icon1"><i><?php echo $count6 ?></i></em><span>待评价</span></a>
            </li>
            <?php if ($level == '3') { ?>
                <li>
                <a href="morder.php?jindu=6"><em class="ordem3"><i><?php echo $count7 ?></i></em><span>已评价</span></a>
                </li><?php } ?>
        </ul>
    </div>
</div>


<!-- 报修信息 -->
<div class="main">
    <div class="weui-cells__title"><i class="fa fa-id-card-o" aria-hidden="true"></i><?php echo $order_title; ?> 任务列表
    </div>
    <!--工单列表开始-->
    <?php
    $sql = "SELECT o.* FROM `#@__order` as o   WHERE   o.is_delete=0  ";
    if (empty($jindu)) {
        if ($level < 3) {
            $sql .= "  AND  o.jindu>'0'  ";
        } elseif ($level = '3' || $level = '4') {
            $sql .= " AND  o.jindu>'2'  ";
        }
    } else {
        $sql .= " AND  o.jindu='$jindu'  ";
    } //进度
    $sql .= "ORDER BY o.id DESC";
    $dopage->GetPage($sql, 8);
    while ($row = $dosql->GetArray()) {
        /*
        进度：
        0 已经撤单
        1 报修成功
        2 客服已经联系
        3 系统已经派单
        4 工程师接单
        5 维修完成
        6 已经评价
        */
        $orderid = $row['id'];
        $jindu2 = intval($row['jindu']);
        $apply_type = $row['apply_type'];
        $apply_device = $row['apply_device'];


        $op_str = '<a class=weui-form-preview__btn weui-form-preview__btn_primary" href="morderDetail.php?orderid=' . $row['id'] . '" ><i class="fa fa-navicon" aria-hidden="true"></i>详情</a>';


        ?>

        <!--工单详情开始-->
        <div class="weui-form-preview">
            <div class="weui-form-preview__bd">
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">工单号：</label>
                    <span class="weui-form-preview__value">
		<?php
        if (!empty($row['poster'])) {
            echo '<i class="fa fa-smile-o blue "></i>';
        }
        if (!empty($row['openid'])) {
            echo '<i class="fa fa-weixin green"></i>';
        }
        ?>
        <?php echo date("Ymd", $row['post_time']) . "-" . $row['id'] ?>
        </span>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">单位：</label>
                    <span class="weui-form-preview__value"><?php echo $row['school'] ?></span></div>
                <?php if (!empty($row['truename'])) { ?>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">联系人：</label>
                        <span class="weui-form-preview__value"><?php echo $row['truename'] ?></span></div>
                <?php } ?>
                <?php if (!empty($row['mobile'])) { ?>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">电话：</label>
                        <span class="weui-form-preview__value"><a href="tel:<?php echo $row['mobile'] ?>"><i class="fa fa-mobile"><?php echo $row['mobile'] ?></a></i></span>
                    </div>
                <?php } ?>
                <?php if (!empty($row['address'])) { ?>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">地址：</label>
                        <span class="weui-form-preview__value" id="daohang" data-orderid="<?php echo $row['id'] ?>"><i class="fa fa-map-marker"><?php echo $row['address'] ?></i></span>
                    </div>
                <?php } ?>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">任务类型：</label>
                    <span class="weui-form-preview__value"><i class="fa  fa-print red"></i> <?php echo getRepairMode($row['apply_device']) ?></span>
                </div>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">故障描述：</label>
                    <span class="weui-form-preview__value"><?php echo $row['content'] ?></span></div>

                <?php if (!empty($row['manageid'])) { ?>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">执行人：</label>
                        <span class="weui-form-preview__value">
			<?php
            if (!empty($row['manageid'])) {
                $m_str = $row['manageid'];
                $m_arr = explode(",", $m_str);
                foreach ($m_arr as $key => $val) {
                    echo ' <i class="fa  fa-user-o red"></i>      ' . getManage($val);
                }
            }
            ?>
        
        </span></div>
                <?php } ?>
                <?php if (!empty($row['begintime'])) { ?>
                    <div class="weui-form-preview__item">
                        <label class="weui-form-preview__label">任务时间：</label>
                        <span class="weui-form-preview__value"><i class="fa fa-play green"></i> <?php echo date("Y-m-d H:i:s", $row['begintime']) . "  
		<br/><i  class=' red fa  fa-stop'></i>     " . date("Y-m-d H:i:s", $row['endtime']) ?></span></div>
                <?php } ?>
                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label red">当前进度：</label>
                    <span class="weui-form-preview__value red"><b><?php echo getJinDuName($row['jindu']) ?></b></span>
                </div>
            </div>
            <div class="weui-form-preview__ft op"> <?php echo $op_str ?> </div>
            <input type="hidden" name="manageid" id="manageid" value="<?php echo $manageid; ?>">
            <div class="juchi"></div>
        </div>
        <!--工单详情结束-->

    <?php } ?>

    <!--工单列表结束-->
</div>
<div class="page-div">

    <?php echo $dopage->GetList(); ?>

</div>
<div class="clear"></div>
<div class="sub_btn"></div>
<script src="lib/jquery-2.1.4.js"></script>
<script src="lib/fastclick.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });

    function jiedan(id) {
        var manageid = $("#manageid").val();
        $.ajax({
            type: 'POST',
            url: "op.php",
            data: {id: id, op: 'jiedan', 'manageid': manageid},
            dataType: 'JSON',
            success: function (result) {
                console.log(result);
                if (result.errno == 0) {
                    console.log(result.msg);
                    if (result.msg === "ok") {
                        $.toast("接单成功", function () {
                            //window.location.reload();
                            window.location.href = "morder.php?jindu=4";
                        });

                    } else {
                        $.alert("接单失败，下手要快哦", "温馨提示");
                    }
                }
            }
        });

    }

    // 微信jssdk
    wx.config({
        debug: false,
        appId: '<?php echo $signPackage["appId"];?>',
        timestamp: <?php echo $signPackage["timestamp"];?>,
        nonceStr: '<?php echo $signPackage["nonceStr"];?>',
        signature: '<?php echo $signPackage["signature"];?>',
        jsApiList: [
            // 所有要调用的 API 都要加到这个列表中
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'openAddress',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'openLocation',
            'getLocation'
        ]
    });
    wx.ready(function () {
        //打开导航
        $("#daohang").on("click", function () {
            var orderid = $(this).data("orderid");
            console.log(orderid);
            $.ajax({
                type: 'POST',
                url: "dingwei.php",
                data: {op: 'dingwei', 'id': orderid},
                dataType: 'JSON',
                success: function (result) {
                    console.log(result);
                    if (result.errno == 0) {
                        console.log(result.msg);
                        if (result.msg === "ok") {
                            wx.openLocation({
                                latitude: result.data.latitude, // 纬度，浮点数，范围为90 ~ -90
                                longitude: result.data.longitude, // 经度，浮点数，范围为180 ~ -180。
                                name: result.data.school, // 位置名
                                address: result.data.address, // 地址详情说明
                                scale: result.data.accuracy, // 地图缩放级别,整形值,范围从1~28。默认为最大

                            });
                        } else {
                            $.alert("获取位置失败，客户没有进行定位", "温馨提示");
                        }
                    }
                }
            });
        })

    })

</script>
<script src="js/jquery-weui.js"></script>
<?php require_once('footer.php'); ?>